package com.example.demo.contrller;

import com.example.demo.contrller.data.ReturnData;
import com.example.demo.contrller.vo.RegisterUser;
import com.example.demo.demos.Admin;
import com.example.demo.demos.Circle;
import com.example.demo.demos.Comment;
import com.example.demo.demos.User;
import com.example.demo.service.AdminService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Resource
    AdminService adminService;
    @PostMapping("/login")
    public ReturnData login(@RequestBody Admin admin){
        return adminService.login(admin.getUsername(),admin.getPassword());
    }

    /**
     * 分页获取所有的用户
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/user/list")
    public ReturnData list(@RequestParam(defaultValue = "1") int page,
                           @RequestParam(defaultValue = "20") int limit,
                           @RequestParam(defaultValue = "") String nickname){
        return adminService.getUserList(page,limit,nickname);
    }
    @PostMapping("/user/delete")
    public ReturnData deleteUser(@RequestBody User user){
        return adminService.deleteUser(user.getId());
    }
    @PostMapping("/updateUserInfo")
    public ReturnData updateUserInfo(@RequestBody RegisterUser user){
        return adminService.updateUserInfo(user);
    }
    @GetMapping("/circle/list")
    public ReturnData getCircle(@RequestParam(defaultValue = "1") int page,
                           @RequestParam(defaultValue = "20") int PageSize,
                           @RequestParam(defaultValue = "") String content){
        return adminService.getCircle(page,PageSize,content);
    }
    @PostMapping("/circle/delete")
    public ReturnData deleteCircle(@RequestBody Circle circle){
        return adminService.deleteCircle(circle.getId());
    }
    @GetMapping("/comment/list")
    public ReturnData getComment(@RequestParam(defaultValue = "1") int page,
                                 @RequestParam(defaultValue = "20") int PageSize,
                                 @RequestParam(defaultValue = "") int circleId){
        return adminService.getComment(page,PageSize,circleId);
    }
    @GetMapping("/comment/delete")
    public ReturnData deleteComment(@RequestBody Comment comment){
        return adminService.deleteComment(comment.getId());
    }
}

